summaryrefslogtreecommitdiff
path: root/app/[lng]/evcp/(evcp)/approval/document-list-only/page.tsx
blob: 5b49a6ef1f7b832e0d682e9d2154ac16c4d8bd5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// evcp/document-list-only/page.tsx - 전체 계약 대상 문서 목록
import * as React from "react"
import { Suspense } from "react"
import { Skeleton } from "@/components/ui/skeleton"
import { type SearchParams } from "@/types/table"
import { getValidFilters } from "@/lib/data-table"
import { DocumentStagesTable } from "@/lib/vendor-document-list/plant/document-stages-table"
import { documentStageSearchParamsCache } from "@/lib/vendor-document-list/plant/document-stage-validations"
import { getDocumentStagesOnly } from "@/lib/vendor-document-list/plant/document-stages-service"

interface IndexPageProps {
  searchParams: Promise<SearchParams>
}

// 문서 테이블 래퍼 컴포넌트 (전체 계약용)
async function DocumentTableWrapper({ 
  searchParams
}: { 
  searchParams: SearchParams
}) {
  const search = documentStageSearchParamsCache.parse(searchParams)
  const validFilters = getValidFilters(search.filters)

  // 필터 타입 변환
  const convertedFilters = validFilters.map(filter => ({
    id: (filter.id || filter.rowId) as string,
    value: filter.value,
    operator: (filter.operator === 'iLike' ? 'ilike' :
               filter.operator === 'notILike' ? 'notin' :
               filter.operator === 'isEmpty' ? 'eq' :
               filter.operator === 'isNotEmpty' ? 'ne' :
               filter.operator === 'isBetween' ? 'eq' :
               filter.operator === 'isRelativeToToday' ? 'eq' :
               filter.operator || 'eq') as 'eq' | 'in' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'like' | 'ilike' | 'notin'
  }))

  // evcp: 전체 계약 대상으로 문서 조회
  const documentsPromise = getDocumentStagesOnly({
    ...search,
    filters: convertedFilters,
  }, -1) // 세션에서 자동으로 도메인 감지

  return (
    <DocumentStagesTable
      promises={Promise.all([documentsPromise])}
      contractId={-1} // 전체 계약을 의미
      projectType="plant" // 기본값으로 plant 사용
    />
  )
}

function TableLoadingSkeleton() {
  return (
    <div className="space-y-4">
      <div className="flex items-center justify-between">
        <Skeleton className="h-6 w-32" />
        <div className="flex items-center gap-2">
          <Skeleton className="h-8 w-20" />
          <Skeleton className="h-8 w-24" />
        </div>
      </div>
      <div className="rounded-md border">
        <div className="p-4">
          <div className="space-y-3">
            {Array.from({ length: 5 }).map((_, i) => (
              <div key={i} className="flex items-center space-x-4">
                <Skeleton className="h-4 w-4" />
                <Skeleton className="h-4 w-24" />
                <Skeleton className="h-4 w-48" />
                <Skeleton className="h-4 w-20" />
                <Skeleton className="h-4 w-16" />
                <Skeleton className="h-4 w-12" />
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  )
}

// 메인 페이지 컴포넌트
export default async function DocumentStagesManagementPage({
  searchParams
}: IndexPageProps) {
  const resolvedSearchParams = await searchParams

  return (
    <div className="mx-auto">
      {/* 문서 테이블 */}
      <Suspense fallback={<TableLoadingSkeleton />}>
        <DocumentTableWrapper 
          searchParams={resolvedSearchParams}
        />
      </Suspense>
    </div>
  )
}